"""用于自我批判和响应优化的反思模块。"""

from typing import Any, Dict, List, Optional
from pydantic import BaseModel
from enum import Enum


class ReflectionType(Enum):
    """反思分析的类型。"""
    ACCURACY = "accuracy"          # 答案在事实层面是否正确？
    COMPLETENESS = "completeness"  # 答案是否充分解答了问题？
    CLARITY = "clarity"            # 答案是否清晰且结构合理？
    RELEVANCE = "relevance"        # 答案与问题是否相关？
    REASONING = "reasoning"        # 推理过程是否合理？
    EVIDENCE = "evidence"          # 答案是否有充分的证据支持？


class ReflectionSeverity(Enum):
    """反思问题的严重程度等级。"""
    CRITICAL = "critical"           # 必须修复
    MAJOR = "major"                 # 应该修复
    MINOR = "minor"                 # 可以改进
    SUGGESTION = "suggestion"       # 可选改进


class ReflectionIssue(BaseModel):
    """在反思过程中发现的问题。"""
    type: ReflectionType  #         类型：反思类型
    severity: ReflectionSeverity    # 严重程度：反思问题的严重程度等级
    description: str                # 描述：问题描述
    suggestion: str                 # 建议：改进建议
    confidence: float               # 置信度：对该问题判断的置信度
    evidence: Optional[str] = None  # 证据：支持该问题的证据（可选）


class CritiqueResult(BaseModel):
    """自我批判分析的结果。"""
    overall_quality: float          # 0.0 ~ 1.0
    confidence: float               # 0.0 ~ 1.0
    issues: List[ReflectionIssue]
    strengths: List[str]
    needs_refinement: bool
    reasoning: str
    metadata: Dict[str, Any]


class RefinementResult(BaseModel):
    """优化响应的结果。"""
    refined_response: str
    improvements_made: List[str]
    quality_improvement: float
    confidence: float
    refinement_reasoning: str
    metadata: Dict[str, Any]
